package com.sangdaelee.callme;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.actionbarsherlock.app.SherlockActivity;

public class IntroActivity extends SherlockActivity {
	
	private ImageView splash;
	private Handler handler;
	
	Runnable irun = new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			intent.setClass(IntroActivity.this, MainActivity.class);
			startActivity(intent);
			IntroActivity.this.finish();
			overridePendingTransition(0, 0);
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.splash);
		
		Animation animation = new AlphaAnimation(0.0f, 1.0f);
		animation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				handler = new Handler();
				handler.postDelayed(irun, 2000);
			}
		});
		
		animation.setDuration(200);
		splash = (ImageView)findViewById(R.id.splash);
		splash.startAnimation(animation);
		
	}
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		handler.removeCallbacks(irun);
		
	}
}
